﻿#ifndef PROTOCOLSWITCHER_H
#define PROTOCOLSWITCHER_H

#include <QObject>
#include <QWidget>
#include <QUdpSocket>
#include <QTcpSocket>
#include <QPushButton>
#include <QTextEdit>
#include <QComboBox>
#include <QVBoxLayout>
#include <QHostAddress>
#include<QTcpServer>
#include<QCheckBox>
#include<QTimer>
#include <QFile>
#include <QDomDocument>
#include <QTextStream>
class Widget;
struct Data {
    quint16 head;
    quint8 type;
    quint8 dataType;
    quint16 dataLong;
    QString info;
    quint16 tail;
};
struct Control
{
    quint16 head;
    quint8 type;
    quint8 saveCon;
    quint16 tail;

};
struct State
{
    quint16 head;
    quint8 type;
    quint8 saveSta;
    quint16 tail;

};
class ProtocolSwitcher : public QWidget
{
    Q_OBJECT

public:
    ProtocolSwitcher(QWidget *parent = nullptr);

    void sendData(QByteArray message);
    void judgeSaveState(QByteArray datagram);
    void TimerExample();
    void loadConfigFromXml(const QString &filePath);
private slots:
    void onProtocolChanged(int index);

    void onSendMessage();

    void onUdpDataReceived();

    void onTcpDataReceived();

    void onTcpConnected();

    void onTcpError(QAbstractSocket::SocketError socketError);

    void onCheckBoxToggled(bool checked);
    void onCycleCheckboxToggled(bool checked);

private:
    QUdpSocket *udpSocket;
    QTcpSocket *tcpSocket;
    QTcpServer *tcpServer;
    QPushButton *sendButton;
    QTextEdit *sendTextEdit;
    QTextEdit *outputTextEdit;
    QTextEdit *sendSourTextEdit;
    QComboBox *protocolComboBox;
    QCheckBox *checkbox;
    QCheckBox *cycleCheckbox;
    QTimer *timer;

    QString udpA_softUnicastHost;
    quint16 udpA_softUnicastPort;

    QString udpA_softMulticastHost;
    quint16 udpA_softMulticastPort;

    QString udpA_softBroadcastHost;
    quint16 udpA_softBroadcastPort;

    QString udpB_softUnicastHost;
    quint16 udpB_softUnicastPort;

    QString udpB_softMulticastHost;
    quint16 udpB_softMulticastPort;

    QString udpB_softBroadcastHost;
    quint16 udpB_softBroadcastPort;

    QString tcpHost;
    quint16 tcpPort;

};

#endif // PROTOCOLSWITCHER_H
